//go:build linux
// +build linux

package main

import (
	"fmt"
	"io"
	"net"
	"os"
	"time"
)

func main() {
	if len(os.Args) != 3 {
		fmt.Fprintf(os.Stderr, "usage: go run sendfile_client.go <serverAddr> <dst>\n")
		os.Exit(1)
	}
	addr := os.Args[1] // 例如 "127.0.0.1:5678"
	dstPath := os.Args[2]

	conn, err := net.DialTimeout("tcp", addr, 3*time.Second)
	if err != nil {
		panic(err)
	}
	defer conn.Close()

	dst, err := os.Create(dstPath)
	if err != nil {
		panic(err)
	}
	defer dst.Close()

	start := time.Now()
	written, err := io.Copy(dst, conn)
	if err != nil {
		panic(err)
	}

	fmt.Printf("[client] received %d bytes in %v\n", written, time.Since(start))
}
